package com.wf.controller;


import com.wf.pojo.Goods;
import com.wf.service.GoodsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/goods")
@Slf4j
public class GoodsController {

    @Autowired
    private GoodsService goodsService;


    /**
     * 根据id查询
     */
    @GetMapping("/{goodsId}")
    public Goods getById(@PathVariable Long goodsId){
        Goods goods=goodsService.getById(goodsId);
        return goods;
    }


    /**
     * 添加商品
     */
    @PostMapping
    public String insert(@RequestBody Goods goods){
        goodsService.insert(goods);
        return "ok";
    }

    /**
     * 更新商品
     */
    @PostMapping("/update")
    public String update(@RequestBody Goods goods){
        goodsService.update(goods);
        return "OK";
    }

    /**
     * 商品上架、下架
     */
    @PostMapping("/status/{status}")
    public String updateByStatus(@PathVariable Integer status,Long id){
        goodsService.updateByStatus(id,status);
        log.info("商品上架：{}，{}",status,id);
        return "ok";
    }

}
